< previous page page_675 next page >

Page 675
Accessing the File System
To prevent harmful scripts from damaging the host computer, VBScript offers some special functions that replace the normal VB functions or perform the same activity in a different way. One major area of difference is in the handling of file access. The standard Visual Basic File input and output commands, as discussed in Chapter 21, "Working with Files," are not available in VBScript. Instead, all file access is provided through the methods and properties of special objects. The objects used in dealing with files are listed in Table 30.4.
Table 30.4 VBScript Objects Used for Working with Files
ObjectDescription
FileA file on the local machine
FolderA folder (directory) on the local machine
DriveA drive on the local machine
TextStreamAn object that provides sequential read/write capability
FileSystemObjectAn object that represents the entire file system, used to reference all the above objects

To perform file and disk operation, use a method or property of an object listed in Table 30.4. The most important object is the FileSystemObject object. You use VBScript's CreateObject function to create a reference to it, as in the following line of code:
Set objFs = CreateObject("Scripting.FileSystemObject")
Obviously, this object gives a malicious programmer a way to damage your system. For this reason, Internet Explorer displays a warning message when VBScript accesses external objects, as shown in Figure 30.6.
0675-01.jpg
Figure 30.6
Internet Explorer has several security
settings to prevent harmful scripts or
controls from running on your computer.
The code in Listing 30.1 displays the last time a user visited a particular Web page. It keeps track of this information by creating a text file called LASTVISIT.TXT in the WINDOWS directory. Open the file in Internet Explorer and click the Refresh button several times to test it.

 
< previous page page_675 next page >